Python generates QR code based on QRCode [Download install call etc.]

  • 2020-06-12 09:32:27
  • OfStack

An example of Python based on QRCode is presented in this paper. To share for your reference, specific as follows:

QR code is a matrix code, or 2-dimensional barcode, which was invented by Denso-ES7en Corporation in Japan in 1994. QR is short for Quick Response, meaning quick response, from the idea that the QR code would allow its contents to be decoded quickly. QR is commonly found in Japan and is the most popular 2-dimensional barcode in the country. The QR code can store more data than the normal bar code, and does not require the scanner to be aligned with the normal bar code when scanning.

qrcode is the third side module of Python and relies on Python image library: PIL(Python Imaging Library)

1. Install qrcode module library

In QRCode website https: / / pypi python. org/pypi/qrcode or https: / / github com/lincolnloop/python - qrcode download module library package

Unzip and use the python setup.py install command to install QRCode

Open the python interpreter: Type import qrcode and install successfully without error

2. Use qrcode module library

Simple to use


import qrcode #  The import module 
img = qrcode.make('Some data here') # QRCode information 
img.save("test.png") #  Save the picture 

Use advanced


import qrcode #  The import module 
qr = qrcode.QRCode(
  version=1,
  error_correction=qrcode.constants.ERROR_CORRECT_L,
  box_size=10,
  border=4,
)
qr.add_data('Some data')
qr.make(fit=True)
img = qr.make_image()
img.save("advanceduse.png")

Parameter definition:

version: Integer values from 1 to 40 that controls the size of the 2-d code (the minimum value is 1, a 21 by 21 matrix). If you want the program to determine automatically, set the value to None and use the fit parameter.
error_correction: Error correction function that controls 2d codes. The following four constants can be taken:
ERROR_CORRECT_L approximately 7% or less of errors can be corrected
ERROR_CORRECT_M (default) approximately 15% or less of errors can be corrected
About 25% or less of ERROR_CORRECT_Q errors can be corrected
About 30% or less of errors can be corrected
box_size: Controls the number of pixels contained in each cell in a 2-dimensional code.
border: The number of cells contained in the control border (the distance between the 2-d code and the image boundary) (the default is 4, which is the minimum specified by the relevant standard)

https QRCode website: / / pypi. python. org/pypi/qrcode

PS: Here is another recommended 2-d code online generation tool for your reference:

Online 2-d code Generation tool (Enhanced)
http://tools.ofstack.com/transcoding/jb51qrcode

For more information about Python, please refer to Python Coding Skills Summary, Python Data Structure and Algorithm Tutorial, Python Function Usage Skills Summary, Python String Manipulation Skills Summary, Python Introduction and Advanced Classic Tutorial and Python File and Directory Operation Skills Summary.

I hope this article has been helpful to you in Python programming.


Related articles: